package com.action;

import java.io.PrintWriter;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionSupport;

import com.bean.*;
import com.dao.*;


public class MyStudentUse extends ActionSupport {

	//下面是Action内用于封装用户请求参数的属性
	private List<LabBean> lablist;
	private List<EquipmentBean> equipmentlist;

	public List<LabBean> getLablist() {
		return lablist;
	}

	public void setLablist(List<LabBean> lablist) {
		this.lablist = lablist;
	}

	public List<EquipmentBean> getEquipmentlist() {
		return equipmentlist;
	}

	public void setEquipmentlist(List<EquipmentBean> equipmentlist) {
		this.equipmentlist = equipmentlist;
	}

	private String LabID;
	private String EquipmentID;
	public String getLabID() {
		return LabID;
	}

	public void setLabID(String labID) {
		LabID = labID;
	}

	public String getEquipmentID() {
		return EquipmentID;
	}

	public void setEquipmentID(String equipmentID) {
		EquipmentID = equipmentID;
	}

	//处理用户请求的execute方法
	public String execute() throws Exception {
		
		//解决乱码，用于页面输出
		HttpServletResponse response=null;
		response=ServletActionContext.getResponse();
		response.setContentType("text/html;charset=UTF-8");
		response.setCharacterEncoding("UTF-8");
		PrintWriter out = response.getWriter();
		
		//创建session对象
		HttpSession session = ServletActionContext.getRequest().getSession();
		//验证是否正常登录
		if(session.getAttribute("id")==null){
			out.print("<script language='javascript'>alert('请重新登录！');window.location='Login.jsp';</script>");
			out.flush();out.close();return null;
		}
		
		//查询实验室
		lablist=new LabDao().GetList("","Lab_Name");
		
		//查询条件
		String strWhere="1=1 ";
		if(!(isInvalid(LabID)))
		{
			strWhere+=" and Equipment_LabID='"+LabID+"'";
		}
		else{
			strWhere+=" and 1=2";
		}
		//查询设备
		equipmentlist=new EquipmentDao().GetList(strWhere,"Equipment_Name");
		
		return SUCCESS;
		
	}
	
	//判断是否空值ֵ
	private boolean isInvalid(String value) {
		return (value == null || value.length() == 0);
	}
	
	//测试
	public static void main(String[] args) {
		System.out.println();
	}
	
}
